package com.orangeandbronze.demos.mapreduce;

import java.nio.ByteBuffer;

import com.google.appengine.tools.mapreduce.Reducer;
import com.google.appengine.tools.mapreduce.ReducerInput;

public class WordCountReducer extends Reducer<String, String[], ByteBuffer> {

	private static final long serialVersionUID = -1102869032227411109L;

	@Override
	public void reduce(String key, ReducerInput<String[]> values) {
		long count = 0;
		while (values.hasNext()) {
			count += ((String[]) values.next()).length;
		}
		getContext().emit(ByteBuffer.wrap((key + ": " + count + "\n").getBytes()));
	}

}
